<template>
  <!-- 全屏 就是一个svg图标-->
  <div style="display:inline-block" @click="hClick">
    <svg-icon :icon-class="isScreenFull ? 'exit-fullscreen': 'fullscreen'" class="fullscreen" />
  </div>
</template>

<script>
import screenfull from 'screenfull'

export default {
  name: 'ScreenFull',
  data() {
    return { isScreenFull: false }
  },
  created() {
    screenfull.on('change', () => {
      console.log('是否全屏', screenfull.isFullscreen)
      this.isScreenFull = screenfull.isFullscreen
    })
  },
  methods: {
    hClick() {
      screenfull.toggle() // 触发change事件
      // this.isScreenFull = !this.isScreenFull
    }
  }
}
</script>

<style lang="scss" scoped>
.fullscreen {
  width: 20px;
  height: 20px;
  color: #fff;
  cursor: pointer;
}
</style>
